<?php


class System_CacheController extends Zend_Controller_Action
{

	private $_html;

	public function deleteAction()
	{
		$this->_helper->viewRenderer->setNoRender(true);
		$directory = WSB_APP_PATH . 'tmp/cache/';
		if(is_dir($directory)) {
			$this->_removeDirectoryRecursive($directory);
		}
		$this->_response->appendBody('<h1>Cache</h1>');
		$this->_response->appendBody('<p>' . $this->_html . '</p>');
		WSB_Log::info('Deleted backend cache');
	}

	private function _removeDirectoryRecursive($dir)
	{
		$dir_contents = scandir($dir);
		foreach ($dir_contents as $item) {
			if (is_dir($dir.$item) && $item != '.' && $item != '..') {
				$this->_removeDirectoryRecursive($dir.$item.'/');
				$this->_html .= "Delete $dir$item/<br />";
			}
			elseif (file_exists($dir.$item) && $item != '.' && $item != '..') {
				if(unlink($dir.$item)) {
					$this->_html .= "Delete $dir$item<br />";
				} else {

				}
			}
		}
		//rmdir($dir);
	}

}
